package com.szbmyoubao.app.ui.webview

import android.webkit.JavascriptInterface
import com.szbmyoubao.app.storage.AppStorage
import com.ellecity06.common.utils.logD

import java.lang.ref.WeakReference

/**
 * @author ellecity06
 * @time 2024/11/4 10:02
 * @des
 */
class CommonWebScript(act: WebActivity) {

    private var activity: WeakReference<WebActivity>? = null

    init {
        activity = WeakReference(act)
    }


    /**
     * 关闭h5页面
     */
    @JavascriptInterface
    fun closeWindow() {
        logD("h5做了关闭操作")
        activity?.get()?.runOnUiThread {
            activity?.get()?.finish()
        }

    }


    /**
     * 给前端传递token
     */
    @JavascriptInterface
    fun getToken(): String? {
        logD("h5页面主动获取token")
        return AppStorage.Companion.token
    }

}